package com.hspedu.set_;

import java.util.HashSet;

@SuppressWarnings({"all"})
public class HashSet01 {
    public static void main(String[] args) {
        HashSet hashSet = new HashSet();

        // 添加失败返回 false 成功返回 true
        System.out.println(hashSet.add("ljt"));// t
        System.out.println(hashSet.add("jack"));// t
        System.out.println(hashSet.add("nike"));// t
        System.out.println(hashSet.add("nike"));// f
        System.out.println(hashSet.add("jay"));// t
        System.out.println(hashSet.add("rose"));// t

        // 指定删除对象
        hashSet.remove("jack");
        System.out.println("set=" + hashSet);

        hashSet = new HashSet();
        hashSet.add("jack");
        hashSet.add("jack");
        hashSet.add(new Dog("tom"));
        hashSet.add(new Dog("tom"));
        System.out.println("set=" + hashSet);

        System.out.println(hashSet.add(new String("ljt")));// t
        System.out.println(hashSet.add(new String("ljt")));// f
        System.out.println("set=" + hashSet);
    }
}

class Dog {
    private  String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Dog(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                '}';
    }

    public Dog() {
    }
}
